import { createResource, createBehavior } from '@inbiz/core';
import { EformHidden } from './locale';

import {
  createInbizSchema,
  createBaseSchema,
  createComponentStyleSchema,
  createDecoratorStyleSchema,
  createModelSchema,
  getDefalutDecoratorProps,
  createComponentLayout,
} from '@inbiz/setters';
import { getPlatform } from '@inbiz/utils';

export const defaultProps = {
  defaultValueType: 'custom',
  systemDefaultValue: 'System_Var_LoginUserID',
  defaultValue: undefined,
};

export const Schema = createInbizSchema({
  attribute: {
    ...createBaseSchema(
      {
        defaultValueType: {
          type: 'string',
          enum: ['system', 'custom'],
          'x-decorator': 'FormItem',
          'x-component': 'Radio.Group',
          // 'x-component': 'Select',
        },
        systemDefaultValue: {
          type: 'string',
          enum: [
            'System_Var_LoginUserID',
            'System_Var_LoginUserIdentityId',
            'System_Var_LoginUserName',
            'System_Var_LoginUserDeptID',
            'System_Var_LoginUserDeptName',
            'System_Var_LoginUserPostID',
            'System_Var_LoginUserPostName',
            'System_Var_LoginUserAccount',
            // 'System_Var_ParentWindowId',
          ],
          'x-decorator': 'FormItem',
          // 'x-component': 'Radio.Group'
          'x-component': 'Select',
          'x-reactions': {
            dependencies: ['.defaultValueType'],
            fulfill: {
              state: {
                hidden: "{{$deps[0] !== 'system'}}",
                // value:"{{$self.value?$self.value:'System_Var_LoginUserID'}}"
              },
            },
          },
        },
        customValue: {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': 'Input',
          'x-reactions': {
            dependencies: ['.defaultValueType'],
            fulfill: {
              state: {
                hidden: "{{$deps[0] !== 'custom'}}",
              },
            },
          },
        },
      },
      {},
      true,
      { hiddenDisplay: true },
    ),
  },
  style: {
    ...createComponentStyleSchema(),
    ...createComponentLayout(),
    ...createDecoratorStyleSchema(),
  },
  senior: {
    ...createModelSchema(),
  },
});

export const Resource = createResource({
  icon: 'Hidden',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'string',
        title: {
          value: 'EformHidden.title',
          status: true,
        },
        'x-decorator': 'FormItem', //FormItemVertical
        'x-component': 'EformHidden',
        'x-component-props': defaultProps,
        'x-decorator-props': getDefalutDecoratorProps(getPlatform()),
      },
    },
  ],
});

export const Behavior = createBehavior({
  name: 'EformHidden',
  extends: ['Field'],
  selector: (node) => node.props?.['x-component'] === 'EformHidden',
  designerProps: { propsSchema: Schema },
  designerLocales: EformHidden,
});
